﻿namespace zijian666.Data;

/// <summary>
/// 数据库操作拦截器接口
/// </summary>
public interface IDbInterceptor
{
    CancellationToken CancellationToken => CancellationToken.None;
    /// <summary>
    /// 命令创建后
    /// </summary>
    ValueTask CommandCreated(DbCommandCreatedInterceptorContext context);

    /// <summary>
    /// 查询命令开始
    /// </summary>
    ValueTask QueryStarting(DbExecuteReaderInterceptorContext context);

    /// <summary>
    /// 查询命令结束
    /// </summary>
    ValueTask QueryExecuted(DbExecuteReaderInterceptorContext context);

    /// <summary>
    /// 非查询命令执行后
    /// </summary>
    ValueTask NonQueryExecuted(DbExecuteNonQueryInterceptorContext context);

    /// <summary>
    /// 事务开始前
    /// </summary>
    ValueTask TransactionStarting(DbTransactionInterceptorContext context);

    /// <summary>
    /// 事务提交
    /// </summary>
    ValueTask TransactionCommitted(DbTransactionInterceptorContext context);
    /// <summary>
    /// 事务回滚
    /// </summary>
    ValueTask TransactionRollbacked(DbTransactionInterceptorContext context);

    /// <summary>
    /// 连接状态变更时（打开/关闭）
    /// </summary>
    ValueTask ConnectionStateChanging(DbConnectionInterceptorContext context);

    /// <summary>
    /// 异常发生时
    /// </summary>
    ValueTask ExceptionOccurred(DbExceptionContext context);

    /// <summary>
    /// 实体插入前
    /// </summary>
    ValueTask EntityInserting(DbEntityInterceptorContext context);
    /// <summary>
    /// 实体更新前
    /// </summary>
    ValueTask EntityUpdateing(DbEntityInterceptorContext context);
    /// <summary>
    /// 实体删除前
    /// </summary>
    ValueTask EntityDeleting(DbEntityInterceptorContext context);


    /// <summary>
    /// 实体插入后
    /// </summary>
    ValueTask EntityInserted(DbEntityInterceptorContext context);
    /// <summary>
    /// 实体更新后
    /// </summary>
    ValueTask EntityUpdated(DbEntityInterceptorContext context);
    /// <summary>
    /// 实体删除后
    /// </summary>
    ValueTask EntityDeleted(DbEntityInterceptorContext context);
}
